<template>
	<div>
		<view class="wrap-list">
			<block v-for="(item, index) in list" :key="index">
				<view class="item">
					<view class="file">
						<image :src="getImageURL(item.cover)" lazy-load @error="onImageError(index)" />
						<view class="status">
							{{ getStatus(item.process) }}
						</view>
					</view>

					<view class="right">
						<view class="title">{{ item.title }}</view>

						<!-- <view class="scrip">{{ item.title }}</view> -->

						<view class="bottom">
							<view class="left">
								<view class="address-bg">
									<image src="/static/images/area.png" />
									<view>{{ item.address }}</view>
								</view>

								<view class="time-bg">
									<image src="/static/images/date.png" />
									<view>{{ item.createAt }}</view>
								</view>
							</view>

							<view class="btn"> {{ getBtnText(item.process) }} </view>
						</view>
					</view>
				</view>
			</block>
		</view>
	</div>
</template>

<script>
	import { getMyCompetitionData } from "@/utils/api";
	export default {
		data() {
			return {
				page: 1,
				total: 0,
				list: [],
			};
		},
		mounted() {
			this.onRefresh();
			uni.$on("onRefresh", () => {
				this.onRefresh();
			});
			uni.$on("onLoadMore", () => {
				this.onLoadMore();
			});
		},
		methods: {
			/**
			 * 图片加载失败
			 */
			onImageError(index) {
				this.list[index].cover = "/static/common/default_icon.png";
			},
			/**
			 * 获取订单状态
			 */
			getStatus(status) {
				let text = "";
				if (status == 0) {
					text = "未开始";
				} else if (status == 1) {
					text = "进行中";
				} else if (sttaus == 2) {
					text = "已结束";
				}
				return text;
			},
			/**
			 * 获取按钮
			 */
			getBtnText(status) {
				let text = "";
				if (status == 0) {
					text = "参赛";
				} else if (status == 1) {
					text = "参赛中";
				} else if (sttaus == 2) {
					text = "成绩";
				}
				return text;
			},
			/**
			 * 刷新
			 */
			onRefresh() {
				this.page = 1;
				this.list = [];
				this.getData();
			},
			/**
			 * 加载更多
			 */
			onLoadMore() {
				if (this.list.length < this.total) {
					this.page++;
					this.getData();
				}
			},
			/**
			 * 网络请求
			 */
			getData() {
				getMyCompetitionData(this.page, "").then((res) => {
					this.total = res.data.total;
					const list = res.data.data;
					if (this.page === 1) {
						this.list = list;
					} else {
						this.list = this.list.concat(list);
					}
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.wrap-list {
		width: 100%;
		overflow: hidden;
		background-color: white;
		padding: 0 30rpx;
		box-sizing: border-box;

		.item {
			width: 100%;
			overflow: hidden;
			padding: 30rpx 0;
			border-bottom: 2rpx solid#E5E5E5;
			display: flex;
			align-items: center;

			&:last-child {
				border-bottom: none;
			}

			.file {
				width: 280rpx;
				height: 186rpx;
				position: relative;
				z-index: 1;
				overflow: hidden;

				> image {
					width: 100%;
					height: 100%;
				}

				.status {
					position: absolute;
					left: 0;
					top: 0;
					z-index: 2;
					width: 116rpx;
					height: 44rpx;
					line-height: 44rpx;
					text-align: center;
					border-bottom-right-radius: 20rpx;
					overflow: hidden;
					background-color: rgba($color: #ea5520, $alpha: 0.5);
					color: white;
					font-size: 24rpx;
				}
			}
			.right {
				margin-left: 25rpx;
				flex: 1;
				overflow: hidden;

				.title {
					color: #333;
					font-size: 30rpx;
					font-weight: bold;
				}

				.scrip {
					margin-top: 20rpx;
					color: #666666;
					font-size: 26rpx;
				}

				.bottom {
					margin-top: 20rpx;
					width: 100%;
					overflow: hidden;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.left {
						flex: 1;
						overflow: hidden;

						.address-bg {
							width: 100%;
							overflow: hidden;
							display: flex;
							align-items: center;

							> image {
								width: 26rpx;
								height: 25rpx;
							}
							> view {
								margin-left: 13rpx;
								color: #999999;
								font-size: 24rpx;
							}
						}
						.time-bg {
							margin-top: 20rpx;
							width: 100%;
							overflow: hidden;
							display: flex;
							align-items: center;
							> image {
								width: 24rpx;
								height: 24rpx;
							}
							> view {
								margin-left: 14rpx;
								color: #999999;
								font-size: 24rpx;
							}
						}
					}

					.btn {
						margin-left: 10rpx;
						width: 126rpx;
						height: 56rpx;
						line-height: 56rpx;
						text-align: center;
						border-radius: 30rpx;
						overflow: hidden;
						background-color: #ea5520;
						color: white;
						font-size: 26rpx;
						display: flex;
						align-items: center;
						justify-content: center;
					}
				}
			}
		}
	}

	view {
		line-height: 1;
	}
</style>
